<?php
declare (strict_types = 1);

namespace app\sk\tpl;
use app\core\Res;


class Base
{
    protected $_index=[];

    public function __construct()
    {
        $this->init();
    }

    // 初始化
    protected function init()
    {}

    public function views(){
        echo $this->header();
        //echo $this->form();
        //echo $this->layuijs([]);

    }

    public function header(){
        $value=
<<<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>账号管理</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/static/assets/libs/layui268/css/layui.css" media="all"/>
<link rel="stylesheet" href="/static/assets/libs/layui-soul-table/soulTable.css" media="all"/>
<link rel="stylesheet" href="/static/assets/module/admin.css"/>
<style type="text/css">
	.red{
		color: red;
		padding-right: 2px;
	}
	.my-input-div{
		display:flex;
		border:none;
		border-bottom: 1px solid #888;
		background-color: #fff;
		height: 28px;
		line-height: 28px;
	}
	.my-input-div:hover,.my-input-div:active,.my-input-div:focus{
		border-bottom: 1px solid #009688;
	}
	.my-input-div:hover i,.my-input-div:active i,.my-input-div:focus i{
		cursor:pointer;
		visibility:visible;
	}	
	.mouse-hand{
		cursor:pointer;
		visibility: hidden;
	}
	.my-input-div .layui-input {
		border-style: none;
	}
	.width-2col{
		width: 564px!important;
	}
	.width-2col .layui-input{
		width: 484px!important;
	}	
</style>
<script type="text/javascript" src="/static/assets/libs/layui268/layui.js"></script> 
<script>
	var exportExcelUrl='';     //导出路径   

	//*******************常用函数******************** */
	
	//数组拼接成URL变量
	function formatDate(_field){
		let a='';
		for(var key in _field){
			if(_field.hasOwnProperty(key)){
				a=a+key+"="+_field[key]+"&";
			}
		}
		a=a.substring(0,a.length-1);
		return a;
	}

	function myIsNaN(value) {
		return (typeof value === 'number' && !isNaN(value));
	}

	//******************************************************** */

	//****************layui 使用变量******************** */
	var $;
	var myTable;
    var laydate;
    var table;
    var soulTable;
	var tableEdit;
    var form;

	var editTableCols;
	var isSave = false;
    var curId=0;

	
	//操作焦点变量
	var focusArea="table";
	var curRowNo = 0;
	var nextRowNo = 1;
	var curColNo = 0;
	var nextColNo = 1;
	var editColNos = [];
	
	//检测变量是否为对象
	function isObject(obj) {
		return Object.prototype.toString.call(obj) === '[object Object]';
	}	
	
    //Layui主配置
    layui.config({
        base: '/static/assets/module/',   // 模块目录
        version: 'v1.6.4'
    }).extend({                         // 模块别名
        tableEdit:'tableEdit',
		soulTable: 'soulTable',
        tableChild: 'tableChild',
		admin:'admin'
    });
</script>
</head>
<body>
EOF;
        return $value;
    }

    public function searchForm1($params){
        $FormId=Res::kv($params,'FormId');
        $hiddenInput=Res::kv($params,'hiddenInput');
        $inputList=Res::kv($params,'inputList');
        $buttonList=Res::kv($params,'buttonList');
        $value=
<<<EOF
<form id="$FormId" lay-filter="$FormId" class="layui-form toolbar">
$hiddenInput
    <div class="layui-form-item" id="search">

        $inputList
        
        $buttonList
    </div>
</form>
        
EOF;
        return $value;
    }

    public function searchTable1($params){
        $TableId=Res::kv($params,'TableId');
        $value=
<<<EOF
<table id="$TableId" lay-filter="$TableId"></table>   
EOF;
        return $value;
    }

    public function formFrame1($params){
        $FormInfo=Res::kv($params,'FormInfo');
        $TableInfo=Res::kv($params,'TableInfo');
        $value=
<<<EOF
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
        $FormInfo
		$TableInfo
        </div>
    </div>
</div>
EOF;
        return $value;
    }

    public function acceptFunction1($params){
        $FunName=Res::kv($params,'FunName');
        $FunInfo=Res::kv($params,'FunInfo');
        $value=
<<<EOF
function $FunName(selectData){
    if(selectData){
        $FunInfo
    }
}
EOF;
        return $value;
    }

    

    public function formInput($params){
        $xinhao=Res::kv($params,'xinhao');
        $titleName=Res::kv($params,'titleName');
        $inputType=Res::kv($params,'inputType');
        $inputName=Res::kv($params,'inputName');
        $verType=Res::kv($params,'verType');
        $verify=Res::kv($params,'verify');
        $onkeyup=Res::kv($params,'onkeyup');
        $disabled=Res::kv($params,'disabled');
        $value=
<<<EOF
<div class="layui-inline">
    <label class="layui-form-label"><span class="red">$xinhao</span>$titleName</label>
    <div class="layui-input-inline">
        <input type="$inputType"  class="layui-input" id="$inputName" name="$inputName" placeholder="$titleName" autocomplete="off" $verType $verify $disabled $onkeyup>	
    </div>			
</div>
EOF;
        return $value;
    }

    public function formOption($params){
        $xinhao=Res::kv($params,'xinhao');
        $titleName=Res::kv($params,'titleName');
        $optionList=Res::kv($params,'optionList');
        $inputName=Res::kv($params,'inputName');
        $verType=Res::kv($params,'verType');
        $verify=Res::kv($params,'verify');
        $disabled=Res::kv($params,'disabled');
        $value=
<<<EOF
<div class="layui-inline">
    <label class="layui-form-label"><span class="red">$xinhao</span>$titleName</label>
    <div class="layui-input-inline">
        <select name="$inputName" id="$inputName" lay-search="" lay-filter="$inputName"  $verType $verify $disabled>
                $optionList
        </select>
    </div>
</div>
EOF;
        return $value;
    }

    public function formButton($params){
        $buttonIcon=Res::kv($params,'buttonIcon');
        $titleName=Res::kv($params,'titleName');
        $buttonName=Res::kv($params,'buttonName');
        $value=
<<<EOF
    <button class="layui-btn icon-btn" lay-filter="$buttonName" lay-submit>
        <i class="layui-icon">$buttonIcon</i>$titleName
    </button>
EOF;
        return $value;
    }

    public function formAddButton($params){
        $buttonIcon=Res::kv($params,'buttonIcon');
        $titleName=Res::kv($params,'titleName');
        $buttonName=Res::kv($params,'buttonName');
        $value=
<<<EOF
<div class="layui-form-item text-right">
    <button class="layui-btn" lay-filter="btnSave" lay-submit>保存</button>
    <button class="layui-btn layui-btn-primary" type="button" mx-event="closeDialog">取消</button>
</div>
EOF;
        return $value;
    }

    public function selectDate1($params){
        $xinhao=Res::kv($params,'xinhao');
        $titleName=Res::kv($params,'titleName');
        $inputName=Res::kv($params,'inputName');
        $verType=Res::kv($params,'verType');
        $verify=Res::kv($params,'verify');
        $disabled=Res::kv($params,'disabled');
        $value=
<<<EOF
<div class="layui-inline">
    <label class="layui-form-label"><span class="red">$xinhao</span>$titleName</label>
    <div class="layui-input-inline">
        <input name="$inputName" class="layui-input" placeholder="选择$titleName" autocomplete="off" $verType $verify $disabled/>
    </div>
</div>
EOF;
        return $value;
    }

    public function selectJsDate1($params){
        $inputName=Res::kv($params,'inputName');
        $value=
<<<EOF
laydate.render({
    elem: '#$inputName',
    type: 'datetime',
});
EOF;
        return $value;
    }

    public function formSearchButton($params){
        $buttonList='';
        foreach($params as $items){
            $buttonList .=$this->formButton($items);
        }
        $value=
<<<EOF
<div class="layui-inline">&emsp;
    $buttonList
</div>
EOF;
        return $value;
    }

    public function hiddenInputList($params){
        $value='';
        foreach($params as $key=>$val){
            $value.=self::hiddenInput($val);
        }
        return $value;
    }

    public function hiddenInput($inputId){
        $value=
<<<EOF
<input id="$inputId" name="$inputId" type="hidden"/>
EOF;
        return $value;
    }

    public function showLayerFormClick($params){
        $funName=Res::kv($params,'funName');
        $inputName=Res::kv($params,'inputName');
        $formName=Res::kv($params,'formName');
        $value=
<<<EOF
$(document).on('click','#$inputName',function (obj) {
    formvar=form.val('$formName');
    $funName(formvar)
});
EOF;
        return $value;
    }

    public function showLayerFun($params){
        $funName=Res::kv($params,'funName');
        $titleName=Res::kv($params,'titleName');
        $width=Res::kv($params,'width');
        $height=Res::kv($params,'height');
        $url=Res::kv($params,'url');
        $value=
<<<EOF
function $funName(fData='') {
    var layIndex = layer.open({
       type: 2,
       title: '$titleName',
       shade: 0.5,
       fixed: false,
       area: ['$width', '$height'],
       content: "$url",
       success: function (layero, index) {
           if(fData){
               var iframe = window['layui-layer-iframe' + index];//拿到iframe元素
               iframe.child(JSON.stringify(fData));//向此iframe层方法 传递参数
           }
       }
   });
}
EOF;
        return $value;
    }
//https://blog.csdn.net/japanstudylang/article/details/89498023
    public function onKeyupMoney(){
        $value=
<<<EOF
onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
EOF;
        return $value;
    }

    public function onKeyupen(){
        $value=
<<<EOF
onkeyup="value="value.replace(/[^a-z]/g,'')"
EOF;
        return $value;
    }

}